
<script setup>
	import list from '@/components/list.vue'
	import { computed, ref } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	import { store } from '@/uni_modules/uni-id-pages/common/store.js'
	
	const data = ref([])
	const info = computed(() => store.userInfo)
	const db = uniCloud.database()
	onLoad(() => {
		getList()
	})
	
	const getList = async () => {
		const res = await db.collection('dynamic_list').where({userId:info.value._id}).orderBy('createTime desc').get()
		data.value = res.result.data
	}
	
	const changeDel = async (event) => {
		const res = await db.collection('dynamic_list').doc(event._id).remove()
		uni.showToast({
			title:'删除成功'
		})
		getList()
	}
</script>

<template>
	<list :data="data" v-if="data.length">
		<template #del="{ item }">
			<view class="delete" @click="changeDel(item)">删除</view>
		</template>
	</list>
	<template v-else>
		<u-empty marginTop="100" mode="list"></u-empty>
	</template>
</template>

<style lang="scss">
	.delete{
		padding: 10rpx 20rpx;
		background: #f00;
		color: #fff;
		font-size: 30rpx;
	}
</style>